package com.navinfo.platform.basicdatastatistics.utils.day;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.navinfo.location.mileage.util.JsonUtil;
import com.navinfo.platform.basicdatastatistics.dto.*;
import com.navinfo.platform.common.utils.DataUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.spark.sql.Row;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.collection.mutable.WrappedArray;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;

public class VehicleBasicDataUtil {
    private static final Logger LOGGER = LoggerFactory.getLogger(VehicleBasicDataUtil.class);
    public static BasicDataDto parseRowToBasicDataDto(Row row) {
        BasicDataDto basicDataDto = new BasicDataDto();
        basicDataDto.setUid(row.getAs("uid"));
        basicDataDto.setTid(row.getAs("tid"));
        basicDataDto.setTimeRanges(row.getAs("time_ranges"));
        basicDataDto.setSharpStepOnGasNumber(row.getAs("sharp_step_on_gas_number"));
        basicDataDto.setTripPower(row.getAs("trip_power"));
        basicDataDto.setTripMileage(row.getAs("trip_mileage"));
        basicDataDto.setTripFuel(row.getAs("trip_fuel"));
        basicDataDto.setTripDuration(row.getAs("trip_duration"));
        basicDataDto.setExceedSpeedRangeMileage(row.getAs("exceed_speed_range_mileage"));
        basicDataDto.setExceedSpeedRangeDuration(row.getAs("exceed_speed_range_duration"));
        basicDataDto.setExceedSpeedRangeFuel(row.getAs("exceed_speed_range_fuel"));
        basicDataDto.setMaxSpeed(row.getAs("max_speed"));
        basicDataDto.setMinSpeed(row.getAs("min_speed"));
        basicDataDto.setMaxUsefulSpeed(row.getAs("max_useful_speed"));
        basicDataDto.setMinUsefulSpeed(row.getAs("min_useful_speed"));
        basicDataDto.setAvgSpeed(DataUtil.remainTwoBit(basicDataDto.getTripMileage(), basicDataDto.getTripDuration()));
        basicDataDto.setInGearCoastMileage(row.getAs("in_gear_coast_mileage"));
        basicDataDto.setInGearCoastDuration(row.getAs("in_gear_coast_duration"));
        basicDataDto.setInGearCoastNumber(row.getAs("in_gear_coast_number"));
        basicDataDto.setBrakeNumber(row.getAs("brake_number"));
        basicDataDto.setBrakeMileage(row.getAs("brake_mileage"));
        basicDataDto.setBrakeDuration(row.getAs("brake_duration"));
        basicDataDto.setVehicleEstimatedLoad(row.getAs("vehicle_estimated_load"));
        basicDataDto.setRouteIntegralMileage(row.getAs("route_integral_mileage"));
        basicDataDto.setRouteIntegralFuel(row.getAs("route_integral_fuel"));
        basicDataDto.setParkingPowerOnDuration(row.getAs("parking_power_on_duration"));
        basicDataDto.setCityDrivingMileage(row.getAs("city_driving_mileage"));
        basicDataDto.setCityDrivingDuration(row.getAs("city_driving_duration"));
        basicDataDto.setCityDrivingFuel(row.getAs("city_driving_fuel"));
        basicDataDto.setRuralDrivingMileage(row.getAs("rural_driving_mileage"));
        basicDataDto.setRuralDrivingDuration(row.getAs("rural_driving_duration"));
        basicDataDto.setRuralDrivingFuel(row.getAs("rural_driving_fuel"));
        basicDataDto.setEcoDrivingMileage(row.getAs("eco_driving_mileage"));
        basicDataDto.setEcoDrivingDuration(row.getAs("eco_driving_duration"));
        basicDataDto.setEcoDrivingFuel(row.getAs("eco_driving_fuel"));
        basicDataDto.setUpSlopeDrivingMileage(row.getAs("up_slope_driving_mileage"));
        basicDataDto.setUpSlopeDrivingDuration(row.getAs("up_slope_driving_duration"));
        basicDataDto.setUpSlopeDrivingFuel(row.getAs("up_slope_driving_fuel"));
        basicDataDto.setDownSlopeDrivingMileage(row.getAs("down_slope_driving_mileage"));
        basicDataDto.setDownSlopeDrivingDuration(row.getAs("down_slope_driving_duration"));
        basicDataDto.setDownSlopeDrivingFuel(row.getAs("down_slope_driving_fuel"));
        basicDataDto.setLevelRoadDrivingMileage(row.getAs("level_road_driving_mileage"));
        basicDataDto.setLevelRoadDrivingDuration(row.getAs("level_road_driving_duration"));
        basicDataDto.setLevelRoadDrivingFuel(row.getAs("level_road_driving_fuel"));
        basicDataDto.setVehicleColdStartMileage(row.getAs("vehicle_cold_start_mileage"));
        basicDataDto.setVehicleColdStartDuration(row.getAs("vehicle_cold_start_duration"));
        basicDataDto.setVehicleColdStartFuel(row.getAs("vehicle_cold_start_fuel"));
        basicDataDto.setSharpTurningNumber(row.getAs("sharp_turning_number"));
        basicDataDto.setCruiseMileage(row.getAs("cruise_mileage"));
        basicDataDto.setCruiseDuration(row.getAs("cruise_duration"));
        basicDataDto.setCruiseFuel(row.getAs("cruise_fuel"));
        basicDataDto.setShiftGearsNumber(row.getAs("shift_gears_number"));
        basicDataDto.setSharpDownSpeedDuration(row.getAs("sharp_down_speed_duration"));
        basicDataDto.setSharpDownSpeedMileage(row.getAs("sharp_down_speed_mileage"));
        basicDataDto.setSharpDownSpeedNumber(row.getAs("sharp_down_speed_number"));
        basicDataDto.setSharpUpSpeedDuration(row.getAs("sharp_up_speed_duration"));
        basicDataDto.setSharpUpSpeedMileage(row.getAs("sharp_up_speed_mileage"));
        basicDataDto.setSharpUpSpeedNumber(row.getAs("sharp_up_speed_number"));
        basicDataDto.setSharpUpSpeedFuel(row.getAs("sharp_up_speed_fuel"));
        basicDataDto.setSharpStepOnGasMileage(row.getAs("sharp_step_on_gas_mileage"));
        basicDataDto.setSharpStepOnGasDuration(row.getAs("sharp_step_on_gas_duration"));
        basicDataDto.setSharpStepOnGasFuel(row.getAs("sharp_step_on_gas_fuel"));
        basicDataDto.setVehicleParkNumber(row.getAs("vehicle_park_number"));
        basicDataDto.setVehicleStartNumber(row.getAs("vehicle_start_number"));
        basicDataDto.setVehicleColdStartNumber(row.getAs("vehicle_cold_start_number"));
        basicDataDto.setChargeFuel(row.getAs("charge_fuel"));
        basicDataDto.setLeakFuel(row.getAs("leak_fuel"));
        basicDataDto.setVehicleStartDuration(row.getAs("vehicle_start_duration"));
        basicDataDto.setVehicleStartFuel(row.getAs("vehicle_start_fuel"));
        basicDataDto.setGasStabilityNumber(row.getAs("gas_stability_number"));
        basicDataDto.setGasStabilityDuration(row.getAs("gas_stability_duration"));
        String crossCities = row.getAs("cross_cities");
        if(StringUtils.isNotEmpty(crossCities)){
            Set<String> crossCitiesSet = new HashSet<>(Arrays.asList(crossCities.split(",")));
            basicDataDto.setCrossCities(StringUtils.join(crossCitiesSet, ","));
        }
        basicDataDto.setAssistBrakeMileage(row.getAs("assist_brake_mileage"));
        basicDataDto.setAssistBrakeDuration(row.getAs("assist_brake_duration"));
        basicDataDto.setFatigueDrivingNumber(row.getAs("fatigue_driving_number"));
        basicDataDto.setParkThrottleDuration(row.getAs("park_throttle_duration"));
        basicDataDto.setParkThrottleFuel(row.getAs("park_throttle_fuel"));
        basicDataDto.setEngineWorkDuration(row.getAs("engine_work_duration"));
        basicDataDto.setDrivingHandbrakeNumber(row.getAs("driving_handbrake_number"));
        basicDataDto.setDrivingHandbrakeDuration(row.getAs("driving_handbrake_duration"));
        basicDataDto.setDrivingHandbrakeMileage(row.getAs("driving_handbrake_mileage"));
        basicDataDto.setIdleHandbrakeNumber(row.getAs("idle_handbrake_number"));
        basicDataDto.setIdleHandbrakeDuration(row.getAs("idle_handbrake_duration"));
        Long mileage = DataUtil.getValue(basicDataDto.getTripMileage(), 0);
        Long tripDuration = DataUtil.getValue(basicDataDto.getTripDuration(), 0);

        //速度区间信息
        calcSpeedInfo(row, basicDataDto);
        //挡位累计
        calcGearInfo(row, basicDataDto);
        //发动机转速区间
        calcRpmRangeInfo(row, basicDataDto);
        //车辆运行水温
        calcWorkWaterTempInfo(row, basicDataDto);
        //怠速水温
        calcIdleWaterTempInfo(row, basicDataDto);
        //油门开度
        calcGasOpenPercent(row, basicDataDto);
        //发动机扭矩
        calcTorqueInfo(row, basicDataDto);
        //发动机进气温度
        calcIatInfo(row, basicDataDto);
        //发动机进气压力
        calcIpInfo(row, basicDataDto);
        //超速90km
        calcSo90(row, basicDataDto, mileage, tripDuration);
        //超速120km
        calcSo120Info(row, basicDataDto, mileage, tripDuration);
        //超转速信息
        calcSrInfo(row, basicDataDto, mileage, tripDuration);
        //低转速（脱档)
        calcLrog(row, basicDataDto, mileage, tripDuration);
        //高速刹车信息
        calcHsbInfo(row, basicDataDto, mileage, tripDuration);
        //普通刹车信息
        calcCsbInfo(row, basicDataDto, mileage, tripDuration);
        //离合相关信息
        calcClutchInfo(row, basicDataDto, mileage, tripDuration);
        //空挡滑行信息
        calcNgCoastInfo(row, basicDataDto, mileage, tripDuration);
        //怠速相关信息
        calcIdleInfo(row, basicDataDto, mileage, tripDuration);
        //海拔相关信息
        calcAltitudeInfo(row, basicDataDto);
        //熄火信息及每个小时车辆的运行状态
        calcFoutAndPerHourState(basicDataDto, mileage, tripDuration);
        calcVehicleHourInfo(row, basicDataDto);
        basicDataDto.setUpdateTime(new Timestamp(System.currentTimeMillis()));

        //add row start
        basicDataDto.setSharpTurningMil(row.getAs("sharp_turning_mil"));
        basicDataDto.setSo90Fuel(row.getAs("so90_fuel"));
        basicDataDto.setSo120Fuel(row.getAs("so120_fuel"));
        basicDataDto.setFatigueDrivingDuration(row.getAs("fatigue_driving_duration"));

        //计算吨/公里
        calcTonKM(row, basicDataDto);

        //计算经过城市详情信息
        calcCrossCitiesInfo(row, basicDataDto);

        //计算满半空状态下的里程和油耗
        calcWloadTypeInfo(row, basicDataDto);

        //计算百公里油耗,单位:L/100KM，100*trip_fuel/trip_mileage'
        calcFuel100km(row, basicDataDto);
        //平均车速(不含怠速)，平均车速(不含怠速)，单位：KM/H，(trip_mileage/1000)/((trip_duration-idle_duration)/3600)
        calcAvgSpeedNoidle(row, basicDataDto);
        //'经济区间占比，单位：%，eco_driving_duration/trip_duration*100'
        calcEcoProportion(row, basicDataDto);
        //当日行程里程之和,1、行程时间大于等于5分钟,行程距离大于等于1千米,百公里油耗大于0小于80,总油耗大于0
        calcTripMileageTotal(row, basicDataDto);
        //刹车次数 "hsb_number+csb_number
        calcBrakeTimes(row, basicDataDto);

        basicDataDto.setSharpUpSpeed1Mileage(row.getAs("sharp_up_speed1_mileage"));
        basicDataDto.setSharpUpSpeed1Fuel(row.getAs("sharp_up_speed1_fuel"));
        basicDataDto.setSharpUpSpeed1Duration(row.getAs("sharp_up_speed1_duration"));
        basicDataDto.setSharpUpSpeed1Number(row.getAs("sharp_up_speed1_number"));
        basicDataDto.setSharpDownSpeed1Mileage(row.getAs("sharp_down_speed1_mileage"));
        basicDataDto.setSharpDownSpeed1Fuel(row.getAs("sharp_down_speed1_fuel"));
        basicDataDto.setSharpDownSpeed1Duration(row.getAs("sharp_down_speed1_duration"));
        basicDataDto.setSharpDownSpeed1Number(row.getAs("sharp_down_speed1_number"));
        basicDataDto.setSharpTurning1Number(row.getAs("sharp_turning1_number"));
        basicDataDto.setLongIdleFuel(row.getAs("long_idle_fuel"));
        basicDataDto.setLongIdleDuration(row.getAs("long_idle_duration"));
        basicDataDto.setLongIdleNumber(row.getAs("long_idle_number"));
        basicDataDto.setColdRunningMileage(row.getAs("cold_running_mileage"));
        basicDataDto.setColdRunningFuel(row.getAs("cold_running_fuel"));
        basicDataDto.setColdRunningDuration(row.getAs("cold_running_duration"));
        basicDataDto.setColdRunningNumber(row.getAs("cold_running_number"));
        basicDataDto.setNightRunningMileage(row.getAs("night_running_mileage"));
        basicDataDto.setNightRunningFuel(row.getAs("night_running_fuel"));
        basicDataDto.setNightRunningDuration(row.getAs("night_running_duration"));
        basicDataDto.setNightRunningNumber(row.getAs("night_running_number"));
        basicDataDto.setHighRotationMileage(row.getAs("high_rotation_mileage"));
        basicDataDto.setHighRotationFuel(row.getAs("high_rotation_fuel"));
        basicDataDto.setHighRotationDuration(row.getAs("high_rotation_duration"));
        basicDataDto.setHighRotationNumber(row.getAs("high_rotation_number"));
        basicDataDto.setLargeGasMileage(row.getAs("large_gas_mileage"));
        basicDataDto.setLargeGasFuel(row.getAs("large_gas_fuel"));
        basicDataDto.setLargeGasDuration(row.getAs("large_gas_duration"));
        basicDataDto.setLargeGasNumber(row.getAs("large_gas_number"));
        basicDataDto.setFullGasMileage(row.getAs("full_gas_mileage"));
        basicDataDto.setFullGasFuel(row.getAs("full_gas_fuel"));
        basicDataDto.setFullGasDuration(row.getAs("full_gas_duration"));
        basicDataDto.setFullGasNumber(row.getAs("full_gas_number"));
        basicDataDto.setFastSpeedMileage(row.getAs("fast_speed_mileage"));
        basicDataDto.setFastSpeedFuel(row.getAs("fast_speed_fuel"));
        basicDataDto.setFastSpeedDuration(row.getAs("fast_speed_duration"));
        basicDataDto.setFastSpeedNumber(row.getAs("fast_speed_number"));
        basicDataDto.setNeutralGearCoast1Mileage(row.getAs("neutral_gear_coast1_mileage"));
        basicDataDto.setNeutralGearCoast1Fuel(row.getAs("neutral_gear_coast1_fuel"));
        basicDataDto.setNeutralGearCoast1Duration(row.getAs("neutral_gear_coast1_duration"));
        basicDataDto.setNeutralGearCoast1Number(row.getAs("neutral_gear_coast1_number"));
        basicDataDto.setFlameoutCoastMileage(row.getAs("flameout_coast_mileage"));
        basicDataDto.setFlameoutCoastFuel(row.getAs("flameout_coast_fuel"));
        basicDataDto.setFlameoutCoastDuration(row.getAs("flameout_coast_duration"));
        basicDataDto.setFlameoutCoastNumber(row.getAs("flameout_coast_number"));

        calScoreInfo(row, basicDataDto);
        calLoadInfo(row, basicDataDto);

        basicDataDto.setGasOpenPercent0Mileage(row.getAs("gas_open_percent0_mileage"));
        basicDataDto.setGasOpenPercent10Mileage(row.getAs("gas_open_percent10_mileage"));
        basicDataDto.setGasOpenPercent20Mileage(row.getAs("gas_open_percent20_mileage"));
        basicDataDto.setGasOpenPercent30Mileage(row.getAs("gas_open_percent30_mileage"));
        basicDataDto.setGasOpenPercent40Mileage(row.getAs("gas_open_percent40_mileage"));
        basicDataDto.setGasOpenPercent50Mileage(row.getAs("gas_open_percent50_mileage"));
        basicDataDto.setGasOpenPercent60Mileage(row.getAs("gas_open_percent60_mileage"));
        basicDataDto.setGasOpenPercent70Mileage(row.getAs("gas_open_percent70_mileage"));
        basicDataDto.setGasOpenPercent80Mileage(row.getAs("gas_open_percent80_mileage"));
        basicDataDto.setGasOpenPercent90Mileage(row.getAs("gas_open_percent90_mileage"));
        basicDataDto.setGasOpenPercent99Mileage(row.getAs("gas_open_percent99_mileage"));
        basicDataDto.setGasOpenPercent100Mileage(row.getAs("gas_open_percent100_mileage"));
        basicDataDto.setGasOpenPercent0Fuel(row.getAs("gas_open_percent0_fuel"));
        basicDataDto.setGasOpenPercent10Fuel(row.getAs("gas_open_percent10_fuel"));
        basicDataDto.setGasOpenPercent20Fuel(row.getAs("gas_open_percent20_fuel"));
        basicDataDto.setGasOpenPercent30Fuel(row.getAs("gas_open_percent30_fuel"));
        basicDataDto.setGasOpenPercent40Fuel(row.getAs("gas_open_percent40_fuel"));
        basicDataDto.setGasOpenPercent50Fuel(row.getAs("gas_open_percent50_fuel"));
        basicDataDto.setGasOpenPercent60Fuel(row.getAs("gas_open_percent60_fuel"));
        basicDataDto.setGasOpenPercent70Fuel(row.getAs("gas_open_percent70_fuel"));
        basicDataDto.setGasOpenPercent80Fuel(row.getAs("gas_open_percent80_fuel"));
        basicDataDto.setGasOpenPercent90Fuel(row.getAs("gas_open_percent90_fuel"));
        basicDataDto.setGasOpenPercent99Fuel(row.getAs("gas_open_percent99_fuel"));
        basicDataDto.setGasOpenPercent100Fuel(row.getAs("gas_open_percent100_fuel"));
        basicDataDto.setTorque0Mileage(row.getAs("torque0_mileage"));
        basicDataDto.setTorque10Mileage(row.getAs("torque10_mileage"));
        basicDataDto.setTorque20Mileage(row.getAs("torque20_mileage"));
        basicDataDto.setTorque30Mileage(row.getAs("torque30_mileage"));
        basicDataDto.setTorque40Mileage(row.getAs("torque40_mileage"));
        basicDataDto.setTorque50Mileage(row.getAs("torque50_mileage"));
        basicDataDto.setTorque60Mileage(row.getAs("torque60_mileage"));
        basicDataDto.setTorque70Mileage(row.getAs("torque70_mileage"));
        basicDataDto.setTorque80Mileage(row.getAs("torque80_mileage"));
        basicDataDto.setTorque90Mileage(row.getAs("torque90_mileage"));
        basicDataDto.setTorque99Mileage(row.getAs("torque99_mileage"));
        basicDataDto.setTorque100Mileage(row.getAs("torque100_mileage"));
        basicDataDto.setTorque0Fuel(row.getAs("torque0_fuel"));
        basicDataDto.setTorque10Fuel(row.getAs("torque10_fuel"));
        basicDataDto.setTorque20Fuel(row.getAs("torque20_fuel"));
        basicDataDto.setTorque30Fuel(row.getAs("torque30_fuel"));
        basicDataDto.setTorque40Fuel(row.getAs("torque40_fuel"));
        basicDataDto.setTorque50Fuel(row.getAs("torque50_fuel"));
        basicDataDto.setTorque60Fuel(row.getAs("torque60_fuel"));
        basicDataDto.setTorque70Fuel(row.getAs("torque70_fuel"));
        basicDataDto.setTorque80Fuel(row.getAs("torque80_fuel"));
        basicDataDto.setTorque90Fuel(row.getAs("torque90_fuel"));
        basicDataDto.setTorque99Fuel(row.getAs("torque99_fuel"));
        basicDataDto.setTorque100Fuel(row.getAs("torque100_fuel"));
        basicDataDto.setTripUrea(row.getAs("trip_urea"));
//        basicDataDto.setUrea100km(row.getAs("urea_100km"));
//        basicDataDto.setUreaFuelRatio(row.getAs("urea_fuel_ratio"));
        //计算百公里油耗,单位:L/100KM，100*trip_fuel/trip_mileage'
        calcUrea100km(row, basicDataDto);
        calcUreaFuelRatio(row, basicDataDto);



        return basicDataDto;
    }

    /**
     * 计算吨/公里
     */
    private static void calcTonKM(Row row, BasicDataDto basicDataDto) {
        WrappedArray.ofRef<Integer> mileage;
        WrappedArray.ofRef<Integer> load;

        try {
            mileage = row.getAs("trip_mileage_list");
            load = row.getAs("trip_load_list");
        }catch (UnsupportedOperationException|IllegalArgumentException e){
            LOGGER.error("计算计算吨/公里失败......", e);
            return;
        }

        int loadSize = load.size();
        List<TonKMDto> tonKMDtos = new ArrayList<>();
        //过滤掉一天的行程数大于50
        for(int i=0; i<mileage.size() && i<50; i++){
            //当载重的为null时，赋值为0
            tonKMDtos.add(new TonKMDto(mileage.apply(i), i<loadSize ? load.apply(i):  0 ));
        }

        basicDataDto.setTonKMDtos(tonKMDtos);
    }

    /**
     * 计算经过城市的详情信息
     */
    private static void calcCrossCitiesInfo(Row row, BasicDataDto basicDataDto) {
        WrappedArray.ofRef<String> cross_cities_list;
        try {
            cross_cities_list = row.getAs("cross_cities_list");
        }catch (UnsupportedOperationException|IllegalArgumentException e){
            LOGGER.error("计算经过城市的详情信息失败......", e);
            return;
        }

        List<InterCrossCity> unionList = new ArrayList();
        String[] cityInfos = cross_cities_list.array();
        for(int i=0; i<cityInfos.length; i++){
            try {
                unionList.addAll(JsonUtil.toList(cityInfos[i], InterCrossCity.class));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        List crossCities = new ArrayList();
        //跨城市去重：AAAABBBAABA -> ABABA
        //过滤掉一天的行程数大于50
        for(int i=0; i<unionList.size() && i<50 ; i++){
            InterCrossCity crossCity = unionList.get(i);
            if(i==0 || crossCity.getLcid()!=unionList.get(i-1).getLcid()){
                crossCities.add(crossCity);
            }
        }

        basicDataDto.setCrossCitiesInfos(crossCities);
    }

    /**
     * 计算满半空状态下的里程和油耗
     * @param row
     * @param basicDataDto
     */
    private static void calcWloadTypeInfo(Row row, BasicDataDto basicDataDto) {
        WrappedArray.ofRef<Integer> mileage;
        WrappedArray.ofRef<Integer> fuel;
        WrappedArray.ofRef<Integer> wloadType;

        try{
            mileage = row.getAs("trip_mileage_list");
            fuel = row.getAs("trip_fuel_list");
            wloadType = row.getAs("wload_type_list");
        }catch (UnsupportedOperationException|IllegalArgumentException e){
            LOGGER.error("计算满半空状态下的里程和油耗......", e);
            return;
        }

        WLoadInfoDto wLoadInfoDto = new WLoadInfoDto();
        Map<String, WLoadInfoDto.WLoadInfo> wLoadInfoMap = wLoadInfoDto.getWLoadInfoMap();
        Integer[] wloadTypeArr = wloadType.array();

        Function<WLoadInfoDto.WLoadInfo, BiFunction<String, WLoadInfoDto.WLoadInfo, WLoadInfoDto.WLoadInfo>> funtion = wLoadInfo1 -> (key, loadInfo) -> {
            return null == loadInfo ? wLoadInfo1 : new WLoadInfoDto.WLoadInfo(wLoadInfo1.getMileage() + loadInfo.getMileage(), wLoadInfo1.getFuel() + loadInfo.getFuel(), wLoadInfo1.getCount() + loadInfo.getCount());
        };

        for(int i=0; i<wloadTypeArr.length; i++){
            WLoadInfoDto.WLoadInfo wLoadInfo = new WLoadInfoDto.WLoadInfo(mileage.apply(i),fuel.apply(i),1);
            switch (wloadTypeArr[i].intValue()){
                case -1:
                    wLoadInfoMap.compute("typeu", funtion.apply(wLoadInfo));
                    break;
                case 0:
                        wLoadInfoMap.compute("type0", funtion.apply(wLoadInfo));
                    break;
                case 1:
                    wLoadInfoMap.compute("type1", funtion.apply(wLoadInfo));
                    break;
                case 2:
                    wLoadInfoMap.compute("type2", funtion.apply(wLoadInfo));
                    break;
                case 3:
                    wLoadInfoMap.compute("type3", funtion.apply(wLoadInfo));
                    break;
                default:
                    break;
            }
        }

        basicDataDto.setWLoadInfoDto(wLoadInfoDto);
    }

    private static void calcVehicleHourInfo(Row row, BasicDataDto basicDataDto) {
        WrappedArray.ofRef array = row.getAs("clock_ranges");
        if(array == null){
            return;
        }
        scala.collection.Iterator<String> clockRangesItor = array.iterator();
        TypeReference<Map<String, VehicleHourInfoDto.VehicleHourBean>> types = new TypeReference<Map<String, VehicleHourInfoDto.VehicleHourBean>>(){};
        Map<String, VehicleHourInfoDto.VehicleHourBean> vehicleHourBeanMap = new HashMap<>();
        VehicleHourInfoDto vehicleHourInfoDto = new VehicleHourInfoDto();
        while(clockRangesItor.hasNext()){
            String hour = clockRangesItor.next();
            Map<String, VehicleHourInfoDto.VehicleHourBean> vehicleHourBeanMapFromJson = JSON.parseObject(hour, types);
            vehicleHourBeanMapFromJson.forEach((key, value) -> {
                String hourKey = "hour" + key;
                VehicleHourInfoDto.VehicleHourBean vehicleHourBean = vehicleHourBeanMap.get(hourKey);
                if (vehicleHourBean == null) {
                    vehicleHourBean = new VehicleHourInfoDto.VehicleHourBean();
                    vehicleHourBean.setState(1);
                    vehicleHourBeanMap.put(hourKey, vehicleHourBean);
                }

                vehicleHourBean.accumulationTime(value.getTime());
                vehicleHourBean.accumulationMileage(value.getMileage());
                vehicleHourBean.accumulationFuel(value.getFuel());
            });
        }
        vehicleHourInfoDto.setVehicleHourBeanMap(vehicleHourBeanMap);
        basicDataDto.setVehicleHourInfoDto(vehicleHourInfoDto);
    }

    private static void calcSpeedInfo(Row row, BasicDataDto basicDataDto) {
        basicDataDto.setSpeedRange01Mileage(row.getAs("speed_range01_mileage"));
        basicDataDto.setSpeedRange01Duration(row.getAs("speed_range01_duration"));
        basicDataDto.setSpeedRange01Fuel(row.getAs("speed_range01_fuel"));
        basicDataDto.setSpeedRange02Mileage(row.getAs("speed_range02_mileage"));
        basicDataDto.setSpeedRange02Duration(row.getAs("speed_range02_duration"));
        basicDataDto.setSpeedRange02Fuel(row.getAs("speed_range02_fuel"));
        basicDataDto.setSpeedRange03Mileage(row.getAs("speed_range03_mileage"));
        basicDataDto.setSpeedRange03Duration(row.getAs("speed_range03_duration"));
        basicDataDto.setSpeedRange03Fuel(row.getAs("speed_range03_fuel"));
        basicDataDto.setSpeedRange04Mileage(row.getAs("speed_range04_mileage"));
        basicDataDto.setSpeedRange04Duration(row.getAs("speed_range04_duration"));
        basicDataDto.setSpeedRange04Fuel(row.getAs("speed_range04_fuel"));
        basicDataDto.setSpeedRange05Mileage(row.getAs("speed_range05_mileage"));
        basicDataDto.setSpeedRange05Duration(row.getAs("speed_range05_duration"));
        basicDataDto.setSpeedRange05Fuel(row.getAs("speed_range05_fuel"));
        basicDataDto.setSpeedRange06Mileage(row.getAs("speed_range06_mileage"));
        basicDataDto.setSpeedRange06Duration(row.getAs("speed_range06_duration"));
        basicDataDto.setSpeedRange06Fuel(row.getAs("speed_range06_fuel"));
        basicDataDto.setSpeedRange07Mileage(row.getAs("speed_range07_mileage"));
        basicDataDto.setSpeedRange07Duration(row.getAs("speed_range07_duration"));
        basicDataDto.setSpeedRange07Fuel(row.getAs("speed_range07_fuel"));
        basicDataDto.setSpeedRange08Mileage(row.getAs("speed_range08_mileage"));
        basicDataDto.setSpeedRange08Duration(row.getAs("speed_range08_duration"));
        basicDataDto.setSpeedRange08Fuel(row.getAs("speed_range08_fuel"));
        basicDataDto.setSpeedRange09Mileage(row.getAs("speed_range09_mileage"));
        basicDataDto.setSpeedRange09Duration(row.getAs("speed_range09_duration"));
        basicDataDto.setSpeedRange09Fuel(row.getAs("speed_range09_fuel"));
        basicDataDto.setSpeedRange10Mileage(row.getAs("speed_range10_mileage"));
        basicDataDto.setSpeedRange10Duration(row.getAs("speed_range10_duration"));
        basicDataDto.setSpeedRange10Fuel(row.getAs("speed_range10_fuel"));
        basicDataDto.setSpeedRange11Mileage(row.getAs("speed_range11_mileage"));
        basicDataDto.setSpeedRange11Duration(row.getAs("speed_range11_duration"));
        basicDataDto.setSpeedRange11Fuel(row.getAs("speed_range11_fuel"));
        basicDataDto.setSpeedRange12Mileage(row.getAs("speed_range12_mileage"));
        basicDataDto.setSpeedRange12Duration(row.getAs("speed_range12_duration"));
        basicDataDto.setSpeedRange12Fuel(row.getAs("speed_range12_fuel"));
    }

    private static void calcGearInfo(Row row, BasicDataDto basicDataDto) {
        basicDataDto.setGear01Mileage(row.getAs("gear01_mileage"));
        basicDataDto.setGear01Fuel(row.getAs("gear01_fuel"));
        basicDataDto.setGear01Duration(row.getAs("gear01_duration"));
        basicDataDto.setGear01Number(row.getAs("gear01_number"));
        basicDataDto.setGear02Mileage(row.getAs("gear02_mileage"));
        basicDataDto.setGear02Fuel(row.getAs("gear02_fuel"));
        basicDataDto.setGear02Duration(row.getAs("gear02_duration"));
        basicDataDto.setGear02Number(row.getAs("gear02_number"));
        basicDataDto.setGear03Mileage(row.getAs("gear03_mileage"));
        basicDataDto.setGear03Fuel(row.getAs("gear03_fuel"));
        basicDataDto.setGear03Duration(row.getAs("gear03_duration"));
        basicDataDto.setGear03Number(row.getAs("gear03_number"));
        basicDataDto.setGear04Mileage(row.getAs("gear04_mileage"));
        basicDataDto.setGear04Fuel(row.getAs("gear04_fuel"));
        basicDataDto.setGear04Duration(row.getAs("gear04_duration"));
        basicDataDto.setGear04Number(row.getAs("gear04_number"));
        basicDataDto.setGear05Mileage(row.getAs("gear05_mileage"));
        basicDataDto.setGear05Fuel(row.getAs("gear05_fuel"));
        basicDataDto.setGear05Duration(row.getAs("gear05_duration"));
        basicDataDto.setGear05Number(row.getAs("gear05_number"));
        basicDataDto.setGear06Mileage(row.getAs("gear06_mileage"));
        basicDataDto.setGear06Fuel(row.getAs("gear06_fuel"));
        basicDataDto.setGear06Duration(row.getAs("gear06_duration"));
        basicDataDto.setGear06Number(row.getAs("gear06_number"));
        basicDataDto.setGear07Mileage(row.getAs("gear07_mileage"));
        basicDataDto.setGear07Fuel(row.getAs("gear07_fuel"));
        basicDataDto.setGear07Duration(row.getAs("gear07_duration"));
        basicDataDto.setGear07Number(row.getAs("gear07_number"));
        basicDataDto.setGear08Mileage(row.getAs("gear08_mileage"));
        basicDataDto.setGear08Fuel(row.getAs("gear08_fuel"));
        basicDataDto.setGear08Duration(row.getAs("gear08_duration"));
        basicDataDto.setGear08Number(row.getAs("gear08_number"));
        basicDataDto.setGear09Mileage(row.getAs("gear09_mileage"));
        basicDataDto.setGear09Fuel(row.getAs("gear09_fuel"));
        basicDataDto.setGear09Duration(row.getAs("gear09_duration"));
        basicDataDto.setGear09Number(row.getAs("gear09_number"));
        basicDataDto.setGear10Mileage(row.getAs("gear10_mileage"));
        basicDataDto.setGear10Fuel(row.getAs("gear10_fuel"));
        basicDataDto.setGear10Duration(row.getAs("gear10_duration"));
        basicDataDto.setGear10Number(row.getAs("gear10_number"));
        basicDataDto.setGear11Mileage(row.getAs("gear11_mileage"));
        basicDataDto.setGear11Fuel(row.getAs("gear11_fuel"));
        basicDataDto.setGear11Duration(row.getAs("gear11_duration"));
        basicDataDto.setGear11Number(row.getAs("gear11_number"));
        basicDataDto.setGear12Mileage(row.getAs("gear12_mileage"));
        basicDataDto.setGear12Fuel(row.getAs("gear12_fuel"));
        basicDataDto.setGear12Duration(row.getAs("gear12_duration"));
        basicDataDto.setGear12Number(row.getAs("gear12_number"));
        basicDataDto.setGear13Mileage(row.getAs("gear13_mileage"));
        basicDataDto.setGear13Fuel(row.getAs("gear13_fuel"));
        basicDataDto.setGear13Duration(row.getAs("gear13_duration"));
        basicDataDto.setGear13Number(row.getAs("gear13_number"));
        basicDataDto.setGear14Mileage(row.getAs("gear14_mileage"));
        basicDataDto.setGear14Fuel(row.getAs("gear14_fuel"));
        basicDataDto.setGear14Duration(row.getAs("gear14_duration"));
        basicDataDto.setGear14Number(row.getAs("gear14_number"));
        basicDataDto.setGear15Mileage(row.getAs("gear15_mileage"));
        basicDataDto.setGear15Fuel(row.getAs("gear15_fuel"));
        basicDataDto.setGear15Duration(row.getAs("gear15_duration"));
        basicDataDto.setGear15Number(row.getAs("gear15_number"));
        basicDataDto.setGear16Mileage(row.getAs("gear16_mileage"));
        basicDataDto.setGear16Fuel(row.getAs("gear16_fuel"));
        basicDataDto.setGear16Duration(row.getAs("gear16_duration"));
        basicDataDto.setGear16Number(row.getAs("gear16_number"));
        basicDataDto.setGearOtherMileage(row.getAs("gear_other_mileage"));
        basicDataDto.setGearOtherFuel(row.getAs("gear_other_fuel"));
        basicDataDto.setGearOtherDuration(row.getAs("gear_other_duration"));
        basicDataDto.setGearOtherNumber(row.getAs("gear_other_number"));
    }

    private static void calcRpmRangeInfo(Row row, BasicDataDto basicDataDto) {
        basicDataDto.setRpmRange500Mileage(row.getAs("rpm_range500_mileage"));
        basicDataDto.setRpmRange500Duration(row.getAs("rpm_range500_duration"));
        basicDataDto.setRpmRange500Fuel(row.getAs("rpm_range500_fuel"));
        basicDataDto.setRpmRange600Mileage(row.getAs("rpm_range600_mileage"));
        basicDataDto.setRpmRange600Duration(row.getAs("rpm_range600_duration"));
        basicDataDto.setRpmRange600Fuel(row.getAs("rpm_range600_fuel"));
        basicDataDto.setRpmRange700Mileage(row.getAs("rpm_range700_mileage"));
        basicDataDto.setRpmRange700Duration(row.getAs("rpm_range700_duration"));
        basicDataDto.setRpmRange700Fuel(row.getAs("rpm_range700_fuel"));
        basicDataDto.setRpmRange800Mileage(row.getAs("rpm_range800_mileage"));
        basicDataDto.setRpmRange800Duration(row.getAs("rpm_range800_duration"));
        basicDataDto.setRpmRange800Fuel(row.getAs("rpm_range800_fuel"));
        basicDataDto.setRpmRange900Mileage(row.getAs("rpm_range900_mileage"));
        basicDataDto.setRpmRange900Duration(row.getAs("rpm_range900_duration"));
        basicDataDto.setRpmRange900Fuel(row.getAs("rpm_range900_fuel"));
        basicDataDto.setRpmRange1000Mileage(row.getAs("rpm_range1000_mileage"));
        basicDataDto.setRpmRange1000Duration(row.getAs("rpm_range1000_duration"));
        basicDataDto.setRpmRange1000Fuel(row.getAs("rpm_range1000_fuel"));
        basicDataDto.setRpmRange1100Mileage(row.getAs("rpm_range1100_mileage"));
        basicDataDto.setRpmRange1100Duration(row.getAs("rpm_range1100_duration"));
        basicDataDto.setRpmRange1100Fuel(row.getAs("rpm_range1100_fuel"));
        basicDataDto.setRpmRange1200Mileage(row.getAs("rpm_range1200_mileage"));
        basicDataDto.setRpmRange1200Duration(row.getAs("rpm_range1200_duration"));
        basicDataDto.setRpmRange1200Fuel(row.getAs("rpm_range1200_fuel"));
        basicDataDto.setRpmRange1300Mileage(row.getAs("rpm_range1300_mileage"));
        basicDataDto.setRpmRange1300Duration(row.getAs("rpm_range1300_duration"));
        basicDataDto.setRpmRange1300Fuel(row.getAs("rpm_range1300_fuel"));
        basicDataDto.setRpmRange1400Mileage(row.getAs("rpm_range1400_mileage"));
        basicDataDto.setRpmRange1400Duration(row.getAs("rpm_range1400_duration"));
        basicDataDto.setRpmRange1400Fuel(row.getAs("rpm_range1400_fuel"));
        basicDataDto.setRpmRange1500Mileage(row.getAs("rpm_range1500_mileage"));
        basicDataDto.setRpmRange1500Duration(row.getAs("rpm_range1500_duration"));
        basicDataDto.setRpmRange1500Fuel(row.getAs("rpm_range1500_fuel"));
        basicDataDto.setRpmRange1600Mileage(row.getAs("rpm_range1600_mileage"));
        basicDataDto.setRpmRange1600Duration(row.getAs("rpm_range1600_duration"));
        basicDataDto.setRpmRange1600Fuel(row.getAs("rpm_range1600_fuel"));
        basicDataDto.setRpmRange1700Mileage(row.getAs("rpm_range1700_mileage"));
        basicDataDto.setRpmRange1700Duration(row.getAs("rpm_range1700_duration"));
        basicDataDto.setRpmRange1700Fuel(row.getAs("rpm_range1700_fuel"));
        basicDataDto.setRpmRange1800Mileage(row.getAs("rpm_range1800_mileage"));
        basicDataDto.setRpmRange1800Duration(row.getAs("rpm_range1800_duration"));
        basicDataDto.setRpmRange1800Fuel(row.getAs("rpm_range1800_fuel"));
        basicDataDto.setRpmRange1900Mileage(row.getAs("rpm_range1900_mileage"));
        basicDataDto.setRpmRange1900Duration(row.getAs("rpm_range1900_duration"));
        basicDataDto.setRpmRange1900Fuel(row.getAs("rpm_range1900_fuel"));
        basicDataDto.setRpmRange2000Mileage(row.getAs("rpm_range2000_mileage"));
        basicDataDto.setRpmRange2000Duration(row.getAs("rpm_range2000_duration"));
        basicDataDto.setRpmRange2000Fuel(row.getAs("rpm_range2000_fuel"));
        basicDataDto.setRpmRange2100Mileage(row.getAs("rpm_range2100_mileage"));
        basicDataDto.setRpmRange2100Duration(row.getAs("rpm_range2100_duration"));
        basicDataDto.setRpmRange2100Fuel(row.getAs("rpm_range2100_fuel"));
        basicDataDto.setRpmRange2200Mileage(row.getAs("rpm_range2200_mileage"));
        basicDataDto.setRpmRange2200Duration(row.getAs("rpm_range2200_duration"));
        basicDataDto.setRpmRange2200Fuel(row.getAs("rpm_range2200_fuel"));
        basicDataDto.setRpmRange2300Mileage(row.getAs("rpm_range2300_mileage"));
        basicDataDto.setRpmRange2300Duration(row.getAs("rpm_range2300_duration"));
        basicDataDto.setRpmRange2300Fuel(row.getAs("rpm_range2300_fuel"));
        basicDataDto.setRpmRange2400Mileage(row.getAs("rpm_range2400_mileage"));
        basicDataDto.setRpmRange2400Duration(row.getAs("rpm_range2400_duration"));
        basicDataDto.setRpmRange2400Fuel(row.getAs("rpm_range2400_fuel"));
        basicDataDto.setRpmRange2500Mileage(row.getAs("rpm_range2500_mileage"));
        basicDataDto.setRpmRange2500Duration(row.getAs("rpm_range2500_duration"));
        basicDataDto.setRpmRange2500Fuel(row.getAs("rpm_range2500_fuel"));
        basicDataDto.setRpmRange2600Mileage(row.getAs("rpm_range2600_mileage"));
        basicDataDto.setRpmRange2600Duration(row.getAs("rpm_range2600_duration"));
        basicDataDto.setRpmRange2600Fuel(row.getAs("rpm_range2600_fuel"));
        basicDataDto.setRpmRange2700Mileage(row.getAs("rpm_range2700_mileage"));
        basicDataDto.setRpmRange2700Duration(row.getAs("rpm_range2700_duration"));
        basicDataDto.setRpmRange2700Fuel(row.getAs("rpm_range2700_fuel"));
        basicDataDto.setRpmRange2800Mileage(row.getAs("rpm_range2800_mileage"));
        basicDataDto.setRpmRange2800Duration(row.getAs("rpm_range2800_duration"));
        basicDataDto.setRpmRange2800Fuel(row.getAs("rpm_range2800_fuel"));
        basicDataDto.setRpmRange2900Mileage(row.getAs("rpm_range2900_mileage"));
        basicDataDto.setRpmRange2900Duration(row.getAs("rpm_range2900_duration"));
        basicDataDto.setRpmRange2900Fuel(row.getAs("rpm_range2900_fuel"));
        basicDataDto.setRpmRange3000Mileage(row.getAs("rpm_range3000_mileage"));
        basicDataDto.setRpmRange3000Duration(row.getAs("rpm_range3000_duration"));
        basicDataDto.setRpmRange3000Fuel(row.getAs("rpm_range3000_fuel"));
        basicDataDto.setRpmRangeOver3000Mileage(row.getAs("rpm_range_over3000_mileage"));
        basicDataDto.setRpmRangeOver3000Duration(row.getAs("rpm_range_over3000_duration"));
        basicDataDto.setRpmRangeOver3000Fuel(row.getAs("rpm_range_over3000_fuel"));
        basicDataDto.setNoIdleRpmSum(row.getAs("no_idle_rpm_sum"));
        basicDataDto.setNoIdleRpmCount(row.getAs("no_idle_rpm_count"));
        basicDataDto.setRpmSum(row.getAs("rpm_sum"));
        basicDataDto.setRpmCount(row.getAs("rpm_count"));
        basicDataDto.setMaxRpm(row.getAs("max_rpm"));
        basicDataDto.setMinRpm(row.getAs("min_rpm"));
        basicDataDto.setAvgRpm(DataUtil.remainTwoBit(basicDataDto.getRpmSum(), basicDataDto.getRpmCount()));
        basicDataDto.setAvgNoIdleRpm(DataUtil.remainTwoBit(basicDataDto.getNoIdleRpmSum(), basicDataDto.getNoIdleRpmCount()));
    }

    private static void calcWorkWaterTempInfo(Row row, BasicDataDto basicDataDto) {
        basicDataDto.setWorkWaterTemp50Duration(row.getAs("work_water_temp50_duration"));
        basicDataDto.setWorkWaterTemp70Duration(row.getAs("work_water_temp70_duration"));
        basicDataDto.setWorkWaterTemp80Duration(row.getAs("work_water_temp80_duration"));
        basicDataDto.setWorkWaterTemp85Duration(row.getAs("work_water_temp85_duration"));
        basicDataDto.setWorkWaterTemp90Duration(row.getAs("work_water_temp90_duration"));
        basicDataDto.setWorkWaterTemp95Duration(row.getAs("work_water_temp95_duration"));
        basicDataDto.setWorkWaterTemp100Duration(row.getAs("work_water_temp100_duration"));
        basicDataDto.setWorkWaterTemp105Duration(row.getAs("work_water_temp105_duration"));
        basicDataDto.setWorkWaterTemp110Duration(row.getAs("work_water_temp110_duration"));
        basicDataDto.setWorkWaterTemp115Duration(row.getAs("work_water_temp115_duration"));
        basicDataDto.setWorkWaterTemp120Duration(row.getAs("work_water_temp120_duration"));
        basicDataDto.setWorkWaterTemp125Duration(row.getAs("work_water_temp125_duration"));
        basicDataDto.setWorkWaterTemp130Duration(row.getAs("work_water_temp130_duration"));
        basicDataDto.setWorkWaterTemp135Duration(row.getAs("work_water_temp135_duration"));
        basicDataDto.setWorkWaterTemp140Duration(row.getAs("work_water_temp140_duration"));
        basicDataDto.setWorkWaterTemp145Duration(row.getAs("work_water_temp145_duration"));
        basicDataDto.setWorkWaterTemp150Duration(row.getAs("work_water_temp150_duration"));
        basicDataDto.setWorkWaterTempOver150Duration(row.getAs("work_water_temp_over150_duration"));
        basicDataDto.setMaxWorkWaterTemp(row.getAs("max_work_water_temp"));
        basicDataDto.setMinWorkWaterTemp(row.getAs("min_work_water_temp"));
        basicDataDto.setWorkWaterTempSum(row.getAs("work_water_temp_sum"));
        basicDataDto.setWorkWaterTempCount(row.getAs("work_water_temp_count"));
        basicDataDto.setAvgWorkWaterTemp(DataUtil.remainTwoBit(basicDataDto.getWorkWaterTempSum(), basicDataDto.getWorkWaterTempCount()));
    }

    private static void calcIdleWaterTempInfo(Row row, BasicDataDto basicDataDto) {
        basicDataDto.setIdleWaterTemp50Duration(row.getAs("idle_water_temp50_duration"));
        basicDataDto.setIdleWaterTemp70Duration(row.getAs("idle_water_temp70_duration"));
        basicDataDto.setIdleWaterTemp80Duration(row.getAs("idle_water_temp80_duration"));
        basicDataDto.setIdleWaterTemp85Duration(row.getAs("idle_water_temp85_duration"));
        basicDataDto.setIdleWaterTemp90Duration(row.getAs("idle_water_temp90_duration"));
        basicDataDto.setIdleWaterTemp95Duration(row.getAs("idle_water_temp95_duration"));
        basicDataDto.setIdleWaterTemp100Duration(row.getAs("idle_water_temp100_duration"));
        basicDataDto.setIdleWaterTemp105Duration(row.getAs("idle_water_temp105_duration"));
        basicDataDto.setIdleWaterTemp110Duration(row.getAs("idle_water_temp110_duration"));
        basicDataDto.setIdleWaterTemp115Duration(row.getAs("idle_water_temp115_duration"));
        basicDataDto.setIdleWaterTemp120Duration(row.getAs("idle_water_temp120_duration"));
        basicDataDto.setIdleWaterTemp125Duration(row.getAs("idle_water_temp125_duration"));
        basicDataDto.setIdleWaterTemp130Duration(row.getAs("idle_water_temp130_duration"));
        basicDataDto.setIdleWaterTemp135Duration(row.getAs("idle_water_temp135_duration"));
        basicDataDto.setIdleWaterTemp140Duration(row.getAs("idle_water_temp140_duration"));
        basicDataDto.setIdleWaterTemp145Duration(row.getAs("idle_water_temp145_duration"));
        basicDataDto.setIdleWaterTemp150Duration(row.getAs("idle_water_temp150_duration"));
        basicDataDto.setIdleWaterTempOver150Duration(row.getAs("idle_water_temp_over150_duration"));
        basicDataDto.setMaxIdleWaterTemp(row.getAs("max_idle_water_temp"));
        basicDataDto.setMinIdleWaterTemp(row.getAs("min_idle_water_temp"));
        basicDataDto.setIdleWaterTempSum(row.getAs("idle_water_temp_sum"));
        basicDataDto.setIdleWaterTempCount(row.getAs("idle_water_temp_count"));
        basicDataDto.setAvgIdleWaterTemp(DataUtil.remainTwoBit(basicDataDto.getIdleWaterTempSum(), basicDataDto.getIdleWaterTempCount()));
    }

    private static void calcGasOpenPercent(Row row, BasicDataDto basicDataDto) {
        basicDataDto.setGasOpenPercent0Duration(row.getAs("gas_open_percent0_duration"));
        basicDataDto.setGasOpenPercent10Duration(row.getAs("gas_open_percent10_duration"));
        basicDataDto.setGasOpenPercent20Duration(row.getAs("gas_open_percent20_duration"));
        basicDataDto.setGasOpenPercent30Duration(row.getAs("gas_open_percent30_duration"));
        basicDataDto.setGasOpenPercent40Duration(row.getAs("gas_open_percent40_duration"));
        basicDataDto.setGasOpenPercent50Duration(row.getAs("gas_open_percent50_duration"));
        basicDataDto.setGasOpenPercent60Duration(row.getAs("gas_open_percent60_duration"));
        basicDataDto.setGasOpenPercent70Duration(row.getAs("gas_open_percent70_duration"));
        basicDataDto.setGasOpenPercent80Duration(row.getAs("gas_open_percent80_duration"));
        basicDataDto.setGasOpenPercent90Duration(row.getAs("gas_open_percent90_duration"));
        basicDataDto.setGasOpenPercent99Duration(row.getAs("gas_open_percent99_duration"));
        basicDataDto.setGasOpenPercent100Duration(row.getAs("gas_open_percent100_duration"));
        basicDataDto.setGasOpenPercentCount(row.getAs("gas_open_percent_count"));
        basicDataDto.setGasOpenPercentSum(row.getAs("gas_open_percent_sum"));
        basicDataDto.setAvgGasOpenPercent(DataUtil.remainTwoBit(basicDataDto.getGasOpenPercentSum(), basicDataDto.getGasOpenPercentCount()));
    }

    private static void calcTorqueInfo(Row row, BasicDataDto basicDataDto) {
        basicDataDto.setTorque0Duration(row.getAs("torque0_duration"));
        basicDataDto.setTorque10Duration(row.getAs("torque10_duration"));
        basicDataDto.setTorque20Duration(row.getAs("torque20_duration"));
        basicDataDto.setTorque30Duration(row.getAs("torque30_duration"));
        basicDataDto.setTorque40Duration(row.getAs("torque40_duration"));
        basicDataDto.setTorque50Duration(row.getAs("torque50_duration"));
        basicDataDto.setTorque60Duration(row.getAs("torque60_duration"));
        basicDataDto.setTorque70Duration(row.getAs("torque70_duration"));
        basicDataDto.setTorque80Duration(row.getAs("torque80_duration"));
        basicDataDto.setTorque90Duration(row.getAs("torque90_duration"));
        basicDataDto.setTorque99Duration(row.getAs("torque99_duration"));
        basicDataDto.setTorque100Duration(row.getAs("torque100_duration"));
        basicDataDto.setMaxTorque(row.getAs("max_torque"));
        basicDataDto.setMinTorque(row.getAs("min_torque"));
        basicDataDto.setTorqueSum(row.getAs("torque_sum"));
        basicDataDto.setTorqueCount(row.getAs("torque_count"));
        basicDataDto.setAvgTorque(DataUtil.remainTwoBit(basicDataDto.getTorqueSum(), basicDataDto.getTorqueCount()));
    }

    private static void calcIatInfo(Row row, BasicDataDto basicDataDto) {
        basicDataDto.setIat50Duration(row.getAs("iat50_duration"));
        basicDataDto.setIat70Duration(row.getAs("iat70_duration"));
        basicDataDto.setIat80Duration(row.getAs("iat80_duration"));
        basicDataDto.setIat85Duration(row.getAs("iat85_duration"));
        basicDataDto.setIat90Duration(row.getAs("iat90_duration"));
        basicDataDto.setIat95Duration(row.getAs("iat95_duration"));
        basicDataDto.setIat100Duration(row.getAs("iat100_duration"));
        basicDataDto.setIat105Duration(row.getAs("iat105_duration"));
        basicDataDto.setIat110Duration(row.getAs("iat110_duration"));
        basicDataDto.setIat115Duration(row.getAs("iat115_duration"));
        basicDataDto.setIat120Duration(row.getAs("iat120_duration"));
        basicDataDto.setIat125Duration(row.getAs("iat125_duration"));
        basicDataDto.setIat130Duration(row.getAs("iat130_duration"));
        basicDataDto.setIat135Duration(row.getAs("iat135_duration"));
        basicDataDto.setIat140Duration(row.getAs("iat140_duration"));
        basicDataDto.setIat145Duration(row.getAs("iat145_duration"));
        basicDataDto.setIat150Duration(row.getAs("iat150_duration"));
        basicDataDto.setIatOver150Duration(row.getAs("iat_over150_duration"));
        basicDataDto.setIatSum(row.getAs("iat_sum"));
        basicDataDto.setIatCount(row.getAs("iat_count"));
        basicDataDto.setMaxIat(row.getAs("max_iat"));
        basicDataDto.setMinIat(row.getAs("min_iat"));
        basicDataDto.setAvgIat(DataUtil.remainTwoBit(basicDataDto.getIatSum(), basicDataDto.getIatCount()));

    }

    /***
     * 发动机进气压力
     * @param row
     * @param basicDataDto
     */
    private static void calcIpInfo(Row row, BasicDataDto basicDataDto) {
        basicDataDto.setIp50Duration(row.getAs("ip50_duration"));
        basicDataDto.setIp60Duration(row.getAs("ip60_duration"));
        basicDataDto.setIp70Duration(row.getAs("ip70_duration"));
        basicDataDto.setIp80Duration(row.getAs("ip80_duration"));
        basicDataDto.setIp90Duration(row.getAs("ip90_duration"));
        basicDataDto.setIp100Duration(row.getAs("ip100_duration"));
        basicDataDto.setIp110Duration(row.getAs("ip110_duration"));
        basicDataDto.setIp120Duration(row.getAs("ip120_duration"));
        basicDataDto.setIp130Duration(row.getAs("ip130_duration"));
        basicDataDto.setIp140Duration(row.getAs("ip140_duration"));
        basicDataDto.setIp150Duration(row.getAs("ip150_duration"));
        basicDataDto.setIpOver150Duration(row.getAs("ip_over150_duration"));
        basicDataDto.setIpSum(row.getAs("ip_sum"));
        basicDataDto.setIpCount(row.getAs("ip_count"));
        basicDataDto.setMaxIp(row.getAs("max_ip"));
        basicDataDto.setMinIp(row.getAs("min_ip"));
        basicDataDto.setAvgIp(DataUtil.remainTwoBit(basicDataDto.getIpSum(), basicDataDto.getIpCount()));
    }

    /***
     * 超速90km
     * @param row
     * @param basicDataDto
     * @param mileage
     * @param tripDuration
     */
    private static void calcSo90(Row row, BasicDataDto basicDataDto, Long mileage, Long tripDuration) {
        basicDataDto.setSo90Number(row.getAs("so90_number"));
        basicDataDto.setSo90Duration(row.getAs("so90_duration"));
        basicDataDto.setSo90Mileage(row.getAs("so90_mileage"));
        basicDataDto.setSo90100kmTimes(DataUtil.hundredKmTimes(basicDataDto.getSo90Number(), mileage));
        basicDataDto.setSo90DurationProportion(DataUtil.durationProportion(basicDataDto.getSo90Duration(), tripDuration));
        basicDataDto.setSo90MileageProportion(DataUtil.mileageProportion(basicDataDto.getSo90Mileage(), mileage));
    }

    /***
     * 超速120km
     * @param row
     * @param basicDataDto
     * @param mileage
     * @param tripDuration
     */
    private static void calcSo120Info(Row row, BasicDataDto basicDataDto, Long mileage, Long tripDuration) {
        basicDataDto.setSo120Number(row.getAs("so120_number"));
        basicDataDto.setSo120Duration(row.getAs("so120_duration"));
        basicDataDto.setSo120Mileage(row.getAs("so120_mileage"));
        basicDataDto.setSo120100kmTimes(DataUtil.hundredKmTimes(basicDataDto.getSo120Number(), mileage));
        basicDataDto.setSo120DurationProportion(DataUtil.durationProportion(basicDataDto.getSo120Duration(), tripDuration));
        basicDataDto.setSo120MileageProportion(DataUtil.mileageProportion(basicDataDto.getSo120Mileage(), mileage));
    }

    /***
     * 超转速信息
     * @param row
     * @param basicDataDto
     * @param mileage
     * @param tripDuration
     */
    private static void calcSrInfo(Row row, BasicDataDto basicDataDto, Long mileage, Long tripDuration) {
        basicDataDto.setSrNumber(row.getAs("sr_number"));
        basicDataDto.setSrDuration(row.getAs("sr_duration"));
        basicDataDto.setSrMileage(row.getAs("sr_mileage"));
        basicDataDto.setSrFuel(row.getAs("sr_fuel"));
        basicDataDto.setSr100kmTimes(DataUtil.hundredKmTimes(basicDataDto.getSrNumber(), mileage));
        basicDataDto.setSrDurationProportion(DataUtil.durationProportion(basicDataDto.getSrDuration(), tripDuration));
        basicDataDto.setSrMileageProportion(DataUtil.mileageProportion(basicDataDto.getSrMileage(), mileage));
    }

    /***
     * 低转速（脱档)
     * @param row
     * @param basicDataDto
     * @param mileage
     * @param tripDuration
     */
    private static void calcLrog(Row row, BasicDataDto basicDataDto, Long mileage, Long tripDuration) {
        basicDataDto.setLrogNumber(row.getAs("lrog_number"));
        basicDataDto.setLrogDuration(row.getAs("lrog_duration"));
        basicDataDto.setLrogMileage(row.getAs("lrog_mileage"));
        basicDataDto.setLrogFuel(row.getAs("lrog_fuel"));
        basicDataDto.setLrog100kmTimes(DataUtil.hundredKmTimes(basicDataDto.getLrogNumber(), mileage));
        basicDataDto.setLrogDurationProportion(DataUtil.durationProportion(basicDataDto.getLrogDuration(), tripDuration));
        basicDataDto.setLrogMileageProportion(DataUtil.mileageProportion(basicDataDto.getLrogMileage(), mileage));
    }

    /***
     * 高速刹车信息
     * @param row
     * @param basicDataDto
     * @param mileage
     * @param tripDuration
     */
    private static void calcHsbInfo(Row row, BasicDataDto basicDataDto, Long mileage, Long tripDuration) {
        basicDataDto.setHsbNumber(row.getAs("hsb_number"));
        basicDataDto.setHsbDuration(row.getAs("hsb_duration"));
        basicDataDto.setHsbMileage(row.getAs("hsb_mileage"));
        basicDataDto.setHsb100kmTimes(DataUtil.hundredKmTimes(basicDataDto.getHsbNumber(), mileage));
        basicDataDto.setHsbDurationProportion(DataUtil.durationProportion(basicDataDto.getHsbDuration(), tripDuration));
        basicDataDto.setHsbMileageProportion(DataUtil.mileageProportion(basicDataDto.getHsbMileage(), mileage));
    }

    /***
     * 普通刹车信息
     * @param row
     * @param basicDataDto
     * @param mileage
     * @param tripDuration
     */
    private static void calcCsbInfo(Row row, BasicDataDto basicDataDto, Long mileage, Long tripDuration) {
        basicDataDto.setCsbNumber(row.getAs("csb_number"));
        basicDataDto.setCsbDuration(row.getAs("csb_duration"));
        basicDataDto.setCsbMileage(row.getAs("csb_mileage"));
        basicDataDto.setCsb100kmTimes(DataUtil.hundredKmTimes(basicDataDto.getCsbNumber(), mileage));
        basicDataDto.setCsbDurationProportion(DataUtil.durationProportion(basicDataDto.getCsbDuration(), tripDuration));
        basicDataDto.setCsbMileageProportion(DataUtil.mileageProportion(basicDataDto.getCsbMileage(), mileage));
    }

    /***
     * 离合相关信息
     * @param row
     * @param basicDataDto
     * @param mileage
     * @param tripDuration
     */
    private static void calcClutchInfo(Row row, BasicDataDto basicDataDto, Long mileage, Long tripDuration) {
        basicDataDto.setClutchNumber(row.getAs("clutch_number"));
        basicDataDto.setClutchDuration(row.getAs("clutch_duration"));
        basicDataDto.setClutchMileage(row.getAs("clutch_mileage"));
        basicDataDto.setClutch100kmTimes(DataUtil.hundredKmTimes(basicDataDto.getClutchNumber(), mileage));
        basicDataDto.setClutchDurationProportion(DataUtil.durationProportion(basicDataDto.getClutchDuration(), tripDuration));
        basicDataDto.setClutchMileageProportion(DataUtil.mileageProportion(basicDataDto.getClutchMileage(), mileage));
    }

    /***
     * 空挡滑行信息
     * @param row
     * @param basicDataDto
     * @param mileage
     * @param tripDuration
     */
    private static void calcNgCoastInfo(Row row, BasicDataDto basicDataDto, Long mileage, Long tripDuration) {
        basicDataDto.setNgCoastNumber(row.getAs("ng_coast_number"));
        basicDataDto.setNgCoastMileage(row.getAs("ng_coast_mileage"));
        basicDataDto.setNgCoastDuration(row.getAs("ng_coast_duration"));
        basicDataDto.setNgCoastFuel(row.getAs("ng_coast_fuel"));
        basicDataDto.setNg100kmTimes(DataUtil.hundredKmTimes(basicDataDto.getNgCoastNumber(), mileage));
        basicDataDto.setNgDurationProportion(DataUtil.durationProportion(basicDataDto.getNgCoastDuration(), tripDuration));
        basicDataDto.setNgMileageProportion(DataUtil.mileageProportion(basicDataDto.getNgCoastMileage(), mileage));
    }

    /***
     * 怠速相关信息
     * @param row
     * @param basicDataDto
     * @param mileage
     * @param tripDuration
     */
    private static void calcIdleInfo(Row row, BasicDataDto basicDataDto, Long mileage, Long tripDuration) {
        basicDataDto.setIdleFuel(row.getAs("idle_fuel"));
        basicDataDto.setIdleDuration(row.getAs("idle_duration"));
        basicDataDto.setIdleNumber(row.getAs("idle_number"));
        basicDataDto.setIdle100kmTimes(DataUtil.hundredKmTimes(basicDataDto.getIdleNumber(), mileage));
        basicDataDto.setIdleDurationProportion(DataUtil.durationProportion(basicDataDto.getIdleDuration(), tripDuration));
        // 新增根据仪表速度=0的怠速油耗、时长、次数
        basicDataDto.setIdleFuelInsSpeed(row.getAs("idle_fuel_instrument_speed"));
        basicDataDto.setIdleDurationInsSpeed(row.getAs("idle_duration_instrument_speed"));
        basicDataDto.setIdleNumberInsSpeed(row.getAs("idle_number_instrument_speed"));
    }

    /***
     * 熄火信息及每个小时车辆的运行状态
     * @param basicDataDto
     * @param mileage
     * @param tripDuration
     */
    private static void calcFoutAndPerHourState(BasicDataDto basicDataDto, Long mileage, Long tripDuration) {
        String timeRanges = basicDataDto.getTimeRanges();
        if(timeRanges != null){
            BitSet bitset = new BitSet(24);
            List<Integer> tripTimes = new ArrayList<>();
            Long foutDuration = 0L;
            Long foutTimes = 0L;
            String[] timeRangeArray = timeRanges.split(",");
            for(String timeRange : timeRangeArray){
                String start = timeRange.split("_")[0];
                String end = timeRange.split("_")[1];
                int startSec = Integer.parseInt(start);
                int endSec = Integer.parseInt(end);
                tripTimes.addAll(Arrays.asList(startSec, endSec));
                Calendar calendar = Calendar.getInstance();
                calendar.setTimeInMillis(startSec * 1000);
                int startHour = calendar.get(Calendar.HOUR_OF_DAY);
                calendar.setTimeInMillis(endSec * 1000);
                int endHour = calendar.get(Calendar.HOUR_OF_DAY);
                for(int s = startHour; s <= endHour; s++){
                    bitset.set(s);
                }
                foutDuration += (endSec - startSec);
            }

            int minSec = Collections.min(tripTimes);
            int maxSec = Collections.max(tripTimes);
            int dayStart = (int)(new DateTime().withTimeAtStartOfDay().getMillis()/1000);
            int dayEnd = (int)((new DateTime().plusDays(1).withTimeAtStartOfDay().getMillis() - 1)/1000);
            if(minSec == dayStart){
                foutTimes++;
            }
            if(maxSec == dayEnd){
                foutTimes++;
            }
            foutTimes += timeRangeArray.length;

            //熄火统计
            basicDataDto.setFoutTimes(foutTimes);
            basicDataDto.setFoutDuration(86400 - foutDuration);
            basicDataDto.setFout100kmTimes(DataUtil.hundredKmTimes(basicDataDto.getFoutTimes(), mileage));
            basicDataDto.setFoutDurationProportion(DataUtil.durationProportion(basicDataDto.getFoutDuration(), tripDuration));

            //每个小时的运行状态
            basicDataDto.setClock0(bitset.get(0) ? 1 : null);
            basicDataDto.setClock1(bitset.get(1) ? 1 : null);
            basicDataDto.setClock2(bitset.get(2) ? 1 : null);
            basicDataDto.setClock3(bitset.get(3) ? 1 : null);
            basicDataDto.setClock4(bitset.get(4) ? 1 : null);
            basicDataDto.setClock5(bitset.get(5) ? 1 : null);
            basicDataDto.setClock6(bitset.get(6) ? 1 : null);
            basicDataDto.setClock7(bitset.get(7) ? 1 : null);
            basicDataDto.setClock8(bitset.get(8) ? 1 : null);
            basicDataDto.setClock9(bitset.get(9) ? 1 : null);
            basicDataDto.setClock10(bitset.get(10) ? 1 : null);
            basicDataDto.setClock11(bitset.get(11) ? 1 : null);
            basicDataDto.setClock12(bitset.get(12) ? 1 : null);
            basicDataDto.setClock13(bitset.get(13) ? 1 : null);
            basicDataDto.setClock14(bitset.get(14) ? 1 : null);
            basicDataDto.setClock15(bitset.get(15) ? 1 : null);
            basicDataDto.setClock16(bitset.get(16) ? 1 : null);
            basicDataDto.setClock17(bitset.get(17) ? 1 : null);
            basicDataDto.setClock18(bitset.get(18) ? 1 : null);
            basicDataDto.setClock19(bitset.get(19) ? 1 : null);
            basicDataDto.setClock20(bitset.get(20) ? 1 : null);
            basicDataDto.setClock21(bitset.get(21) ? 1 : null);
            basicDataDto.setClock22(bitset.get(22) ? 1 : null);
            basicDataDto.setClock23(bitset.get(23) ? 1 : null);
        }
    }

    /***
     * 海拔相关信息
     * @param row
     * @param basicDataDto
     */
    private static void calcAltitudeInfo(Row row, BasicDataDto basicDataDto) {
        WrappedArray.ofRef array = row.getAs("altitude_ranges");
        if(array == null){
            return;
        }
        scala.collection.Iterator<String> altitudeItor = array.iterator();
        TypeReference<Map<String, AltitudeDto>> types = new TypeReference<Map<String, AltitudeDto>>(){};
        Map<String, AltitudeDto> altitudeDtoMap = new HashMap<>();
        while(altitudeItor.hasNext()){
            String altitude = altitudeItor.next();
            Map<String, AltitudeDto> altitudeTempMap = JSON.parseObject(altitude, types);
            altitudeTempMap.forEach((key, value) -> {
                String askKey = "asl" + key;
                AltitudeDto altitudeDto = altitudeDtoMap.get(askKey);
                if (altitudeDto == null) {
                    altitudeDto = new AltitudeDto();
                    altitudeDtoMap.put(askKey, altitudeDto);
                }
                altitudeDto.setFuel(altitudeDto.getFuel() + value.getFuel());
                altitudeDto.setMileage(altitudeDto.getMileage() + value.getMileage());
                altitudeDto.setTime(altitudeDto.getTime() + value.getTime());
            });
        }

        if(altitudeDtoMap.isEmpty()){
            return;
        }
        basicDataDto.setAltitudeDtoMap(altitudeDtoMap);




//        AltitudeDto aslNegInfinityNeg500 = altitudeDtoMap.get(0);
//        if(aslNegInfinityNeg500 != null){
//            basicDataDto.setAslNegInfinityNeg500Time(aslNegInfinityNeg500.getTime());
//            basicDataDto.setAslNegInfinityNeg500Mileage(aslNegInfinityNeg500.getMileage());
//            basicDataDto.setAslNegInfinityNeg500Fuel(aslNegInfinityNeg500.getFuel());
//        }
//
//        AltitudeDto aslNeg500 = altitudeDtoMap.get(1);
//        if(aslNeg500 != null){
//            basicDataDto.setAslNeg500Time(aslNeg500.getTime());
//            basicDataDto.setAslNeg500Mileage(aslNeg500.getMileage());
//            basicDataDto.setAslNeg500Fuel(aslNeg500.getFuel());
//        }
//
//        AltitudeDto aslZero = altitudeDtoMap.get(2);
//        if(aslZero != null){
//            basicDataDto.setAslZeroTime(aslZero.getTime());
//            basicDataDto.setAslZeroMileage(aslZero.getMileage());
//            basicDataDto.setAslZeroFuel(aslZero.getFuel());
//        }
//
//        AltitudeDto asl500 = altitudeDtoMap.get(3);
//        if(asl500 != null){
//            basicDataDto.setAsl500Time(asl500.getTime());
//            basicDataDto.setAsl500Mileage(asl500.getMileage());
//            basicDataDto.setAsl500Fuel(asl500.getFuel());
//        }
//
//        AltitudeDto asl1000 = altitudeDtoMap.get(4);
//        if(asl1000 != null){
//            basicDataDto.setAsl1000Time(asl1000.getTime());
//            basicDataDto.setAsl1000Mileage(asl1000.getMileage());
//            basicDataDto.setAsl1000Fuel(asl1000.getFuel());
//        }
//
//
//        AltitudeDto asl1500 = altitudeDtoMap.get(5);
//        if(asl1500 != null){
//            basicDataDto.setAsl1500Time(asl1500.getTime());
//            basicDataDto.setAsl1500Mileage(asl1500.getMileage());
//            basicDataDto.setAsl1500Fuel(asl1500.getFuel());
//        }
//
//        AltitudeDto asl2000 = altitudeDtoMap.get(6);
//        if(asl2000 != null){
//            basicDataDto.setAsl2000Time(asl2000.getTime());
//            basicDataDto.setAsl2000Mileage(asl2000.getMileage());
//            basicDataDto.setAsl2000Fuel(asl2000.getFuel());
//        }
//
//        AltitudeDto asl2500 = altitudeDtoMap.get(7);
//        if(asl2500 != null){
//            basicDataDto.setAsl2500Time(asl2500.getTime());
//            basicDataDto.setAsl2500Mileage(asl2500.getMileage());
//            basicDataDto.setAsl2500Fuel(asl2500.getFuel());
//        }
//
//        AltitudeDto asl3000 = altitudeDtoMap.get(8);
//        if(asl3000 != null){
//            basicDataDto.setAsl3000Time(asl3000.getTime());
//            basicDataDto.setAsl3000Mileage(asl3000.getMileage());
//            basicDataDto.setAsl3000Fuel(asl3000.getFuel());
//        }
//
//        AltitudeDto asl3500 = altitudeDtoMap.get(9);
//        if(asl3500 != null){
//            basicDataDto.setAsl3500Time(asl3500.getTime());
//            basicDataDto.setAsl3500Mileage(asl3500.getMileage());
//            basicDataDto.setAsl3500Fuel(asl3500.getFuel());
//        }
//
//        AltitudeDto asl4000 = altitudeDtoMap.get(10);
//        if(asl4000 != null){
//            basicDataDto.setAsl4000Time(asl4000.getTime());
//            basicDataDto.setAsl4000Mileage(asl4000.getMileage());
//            basicDataDto.setAsl4000Fuel(asl4000.getFuel());
//        }
//
//        AltitudeDto asl4500 = altitudeDtoMap.get(11);
//        if(asl4500 != null){
//            basicDataDto.setAsl4500Time(asl4500.getTime());
//            basicDataDto.setAsl4500Mileage(asl4500.getMileage());
//            basicDataDto.setAsl4500Fuel(asl4500.getFuel());
//        }
//
//        AltitudeDto asl5000 = altitudeDtoMap.get(12);
//        if(asl5000 != null){
//            basicDataDto.setAsl5000Time(asl5000.getTime());
//            basicDataDto.setAsl5000Mileage(asl5000.getMileage());
//            basicDataDto.setAsl5000Fuel(asl5000.getFuel());
//        }
//
//        AltitudeDto asl5500 = altitudeDtoMap.get(13);
//        if(asl5500 != null){
//            basicDataDto.setAsl5500Time(asl5500.getTime());
//            basicDataDto.setAsl5500Mileage(asl5500.getMileage());
//            basicDataDto.setAsl5500Fuel(asl5500.getFuel());
//        }
    }
    /***
     * 百公里油耗，单位:L/100KM，100*trip_fuel/trip_mileage
     * @param row
     * @param basicDataDto
     */
    private static void calcFuel100km(Row row, BasicDataDto basicDataDto) {
        Long trip_fuel = row.getAs("trip_fuel");
        Long trip_mileage = row.getAs("trip_mileage");
        if(trip_mileage != 0){
            basicDataDto.setFuel100km(DataUtil.remainTwoBit(trip_fuel, trip_mileage));
        }else{
            basicDataDto.setFuel100km(new Long(0));
        }
    }

    /***
     * 平均车速(不含怠速)，单位：100* KM/H，
     *  (trip_mileage/1000)/((trip_duration-idle_duration)/3600)
     * @param row
     * @param basicDataDto
     */
    private static void calcAvgSpeedNoidle(Row row, BasicDataDto basicDataDto) {
        Long trip_mileage = row.getAs("trip_mileage");
        Long trip_duration = row.getAs("trip_duration");
        Long idle_duration =row.getAs("idle_duration");
        if(trip_duration-idle_duration!=0){
            basicDataDto.setAvgSpeedNoidle(DataUtil.remainTwoBit(trip_mileage * 3.6, (trip_duration - idle_duration)));
        }else{
            basicDataDto.setAvgSpeedNoidle(new Long(0));
        }
    }
    /***
     * 经济区间占比，单位：%，
     * eco_driving_duration/trip_duration*100'
     * @param row
     * @param basicDataDto
     */
    private static void calcEcoProportion(Row row, BasicDataDto basicDataDto) {
        Long eco_driving_duration = row.getAs("eco_driving_duration");
        Long trip_duration = row.getAs("trip_duration");
        if(trip_duration != 0 ){
            basicDataDto.setEcoProportion(DataUtil.remainTwoBit(eco_driving_duration, trip_duration));
        }else{
            basicDataDto.setEcoProportion(new Long(0));
        }


    }
    /***
     * 当日行程里程之和，单位：m，
     * 1、行程时间大于等于5分钟,行程距离大于等于1千米,
     *    百公里油耗大于0小于80,总油耗大于0''
     * @param row
     * @param basicDataDto
     */
    private static void calcTripMileageTotal(Row row, BasicDataDto basicDataDto) {
        WrappedArray.ofRef<Integer> mileage;
        WrappedArray.ofRef<Integer> fuel;
        WrappedArray.ofRef<Integer> duration;
        WrappedArray.ofRef<Integer> cross_day_flag;
        Long tripMileageTotal = 0L;
        int fuel_100km = 0;
        try{
            mileage = row.getAs("trip_mileage_list");
            fuel = row.getAs("trip_fuel_list");
            duration = row.getAs("trip_duration_list");
            cross_day_flag = row.getAs("cross_day_flag_list");
        }catch (UnsupportedOperationException|IllegalArgumentException e){
            LOGGER.error("计算当日行程里程和......", e);
            return;
        }
        for(int i=0; i<mileage.size(); i++) {
           if (mileage.apply(i) == 0){
               fuel_100km = 0 ;
           }else{
               fuel_100km = DataUtil.remainTwoBit(fuel.apply(i),mileage.apply(i));
           }


            if(mileage.apply(i)>1000 && duration.apply(i)>300 && fuel.apply(i)>0 && fuel_100km>0 && fuel_100km <8000 && cross_day_flag.apply(i) == 0 ){
                tripMileageTotal = tripMileageTotal + mileage.apply(i);
            }
        }
        basicDataDto.setTripMileageTotal(tripMileageTotal);

    }
    /***
     * 刹车次数 "hsb_number+csb_number
     * @param row
     * @param basicDataDto
     */
    private static void calcBrakeTimes(Row row, BasicDataDto basicDataDto){
        Long hsb_number = row.getAs("hsb_number");
        Long csb_number = row.getAs("csb_number");
        basicDataDto.setBrakeTimes(Optional.ofNullable(hsb_number).orElse(new Long(0)) + Optional.ofNullable(csb_number).orElse(new Long(0)));

    }

    /**
     * 计算载重信息
     */
    private static void calLoadInfo(Row row, BasicDataDto basicDataDto) {
        WrappedArray.ofRef<Integer> amt_load_list;
        WrappedArray.ofRef<Integer> vecu_load_list;
        WrappedArray.ofRef<Integer> load_type_list;
        try {
            amt_load_list = row.getAs("amt_load_list");
            vecu_load_list = row.getAs("vecu_load_list");
            load_type_list = row.getAs("load_type_list");



        int amtLoadSize = amt_load_list.size();
        int vecuLoadSize = vecu_load_list.size();
        int loadTypeSize = load_type_list.size();
        List<LoadInfo> loadInfos = new ArrayList<>();
        //过滤掉一天的行程数大于50
        for(int i=0; i<loadTypeSize ; i++){

            loadInfos.add(new LoadInfo(load_type_list.apply(i),new Integer(i<amtLoadSize ? amt_load_list.apply(i):  0 ),new Integer(i<vecuLoadSize ? vecu_load_list.apply(i):  0)));
        }

        basicDataDto.setLoadInfos(loadInfos);

        }catch (UnsupportedOperationException|IllegalArgumentException e){
            LOGGER.error("计算载重的详情信息失败......", e);
            return;
        }
    }

    /**
     * 计算得分信息
     */
    private static void calScoreInfo(Row row, BasicDataDto basicDataDto) {
        WrappedArray.ofRef<Integer> totalScore_list;
        WrappedArray.ofRef<Integer> safeScore_list;
        WrappedArray.ofRef<Integer> ecoScore_list;
        try {
            totalScore_list = row.getAs("totalScore_list");
            safeScore_list = row.getAs("safeScore_list");
            ecoScore_list = row.getAs("ecoScore_list");

        int totalScoreSize = totalScore_list.size();
        int safeScoreSize = safeScore_list.size();
        int ecoScoreSize = ecoScore_list.size();
        List<ScoreInfo> scoreInfos = new ArrayList<>();

        for(int i=0; i<totalScoreSize ; i++){

            scoreInfos.add(new ScoreInfo(totalScore_list.apply(i),new Integer(i<safeScoreSize ? safeScore_list.apply(i):  0),new Integer(i<ecoScoreSize ? ecoScore_list.apply(i):  0 )));
        }

        basicDataDto.setScoreInfos(scoreInfos);

        }catch (UnsupportedOperationException|IllegalArgumentException e){
            LOGGER.error("计算得分的详情信息失败......", e);
            return;
        }


    }

    /***
     * 百公里尿素消耗，单位:L/100KM，100*urea_injection/trip_mileage
     * @param row
     * @param basicDataDto
     */
    private static void calcUrea100km(Row row, BasicDataDto basicDataDto) {
        Long trip_urea = row.getAs("trip_urea");
        Long trip_mileage = row.getAs("trip_mileage");
        if(trip_mileage != 0 && null != trip_urea){
            basicDataDto.setUrea100km(DataUtil.remainTwoBit(trip_urea*100, trip_mileage));
        }else{
            basicDataDto.setUrea100km(new Long(0));
        }
    }
    /***
     * 尿燃比，单位:L/100KM，100*urea_injection/trip_mileage
     *
     * @param row
     * @param basicDataDto
     */
    private static void calcUreaFuelRatio(Row row, BasicDataDto basicDataDto) {
        Long trip_urea = row.getAs("trip_urea");
        Long trip_fuel = row.getAs("trip_fuel");
        if(trip_fuel != 0 && null != trip_urea ){
            basicDataDto.setUreaFuelRatio(DataUtil.remainTwoBit(trip_urea * 100, trip_fuel));
        }else{
            basicDataDto.setUreaFuelRatio(new Long(0));
        }
    }
}
